package cn.mrlong.tools.bean

import cn.mrlong.tools.util.ImageRecordUtil.convertToList
import com.fasterxml.jackson.annotation.JsonIgnore
import java.util.*

/**
 * @author LeeWyatt
 */
class Note : Record {
    var chapterId: Int? = null

    //public List<ImageRecord> getImageRecords() {
    //    return imageRecords;
    //}
    //
    //public void setImageRecords(List<ImageRecord> imageRecords) {
    //    this.imageRecords = imageRecords;
    //}
    var notebookId: Int? = null

    var content: String? = null

    var description: String? = null

    var source: String? = null

    var offsetStart: Int = 0

    var offsetEnd: Int = 0

    var type: String? = null

    var imageRecords: String? = null

    val imageRecordList: List<ImageRecord>?
        get() = convertToList(imageRecords)

    constructor()

    constructor(title: String?, notebookId: Int?, chapterId: Int?, createTime: Long?, updateTime: Long? = createTime) {
        this.title = title
        this.notebookId = notebookId
        this.chapterId = chapterId
        this.createTime = createTime
        this.updateTime = updateTime
    }


    /**
     * 遇见了一个坑;重写equals方法,忘记了带上父类的属性
     * 由于子类的属性完全相同. 交所以导致同一章节下的很多note都返回true. 导致List的indexOf方法找不到正确的结果
     */
    override fun equals(o: Any?): Boolean {
        if (this === o) {
            return true
        }
        if (o == null || javaClass != o.javaClass) {
            return false
        }
        val note = o as Note
        return id == note.id && title == note.title && showOrder == note.showOrder && createTime == note.createTime && updateTime == note.updateTime && chapterId == note.chapterId && notebookId == note.notebookId && content == note.content && description == note.description && source == note.source && type == note.type && (offsetStart == note.offsetStart) && (offsetEnd == note.offsetEnd)
    }

    override fun hashCode(): Int {
        return Objects.hash(id, title, showOrder, createTime, updateTime, chapterId, notebookId, content, description, source, offsetStart, offsetEnd, type)
    }
}